//
//  ShopMainPageCellLeftTableViewCell.m
//  BaseFrame
//
//  Created by ENERGY on 2018/5/11.
//  Copyright © 2018年 com.mxh. All rights reserved.
//

#import "ShopMainPageCellLeftTableViewCell.h"

@interface ShopMainPageCellLeftTableViewCell()
Strong UILabel *titleLabel;
Strong UIView *line1View;
Strong UIView *lineView;
Strong UIView *line2View;
Strong UIImageView * produceImg;//商品图片

@end

@implementation ShopMainPageCellLeftTableViewCell

- (id)initWithCellIdentifier:(NSString *)cellID{
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _titleLabel  = [[UILabel alloc]init];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(textColor);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.text = @"分类名称";
        [self.contentView addSubview:_titleLabel];
        
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = getColor(dividerColor);
        [self.contentView addSubview:_lineView];
        
        _line1View = [[UIView alloc]init];
//        _line1View.backgroundColor = getColor(mainColor);
        _line1View.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_line1View];
        
        _line2View = [[UIView alloc]init];
        _line2View.backgroundColor = getColor(dividerColor);
        [self.contentView addSubview:_line2View];
        
        _produceImg = [[UIImageView alloc] init];
        _produceImg.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_produceImg];

        [self layoutFrame];
    }
    return self;
}

- (void)layoutFrame{
    __weak __typeof(self)weakSelf = self;
    [self.line1View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(1);
        make.bottom.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(2 / WIDTH_5S_SCALE);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(0.5);
    }];
    
    [self.produceImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(5/WIDTH_5S_SCALE);
        make.right.equalTo(self.titleLabel.mas_left).offset(-5/WIDTH_5S_SCALE);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.height.width.mas_equalTo(25/WIDTH_5S_SCALE);
//        make.width.mas_equalTo(25/wid)
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(0);
//        make.right.mas_equalTo(0);
//        make.top.mas_equalTo(0);
//        make.bottom.mas_equalTo(0);
        make.centerY.height.mas_equalTo(self.produceImg);
        make.right.equalTo(self.mas_right).offset(-5/WIDTH_5S_SCALE);
    }];
    
    [self.line2View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0 / WIDTH_5S_SCALE);
        make.bottom.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.line1View.hidden = YES;
    self.lineView.hidden = NO;
    if ([self.chooseIndex intValue] == self.indexPath.row) {
        self.line1View.hidden = NO;
        self.lineView.hidden = YES;
    }
    UIImageView *titleImageView = [UIImageView new];
    [titleImageView sd_setImageWithURL:[NSURL URLOffsetIPWithString:model[@"cc_picture"]]];
    
    NSMutableAttributedString *attStr1 = [NSMutableAttributedString new];
    NSTextAttachment *seeAtt1 = [NSTextAttachment new];
    seeAtt1.bounds = CGRectMake(0, -2, 15, 10);
    seeAtt1.image = titleImageView.image;
    [attStr1 appendAttributedString:[NSAttributedString attributedStringWithAttachment:seeAtt1]];
    [attStr1 appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"  %@",model[@"cc_name"]]]];
    self.titleLabel.attributedText = attStr1;
}

@end
